<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class User extends Model
{
//    绑定所操作的数据表
    protected $table='week_three_exam_user';

    /**
     * @param $data
     * @return array|bool|\PDOStatement|string|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 登陆的方法
     */
    public function checkLogin($data){
        //查询数据是否在表中
        return $this->where('tel',$data['tel'])->where('password',encrypt_password($data['password']))->find();
    }


    /**
     * @param $data
     * @return array|bool|\PDOStatement|string|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 查询旧密码是否正确
     */
    public function checkPassword($data){
        return $this->where('password',encrypt_password($data['oldPassword']))->find();
    }


    /**
     * @param $data
     * @return User
     * 修改密码的方法
     */
    public function updatePwd($data){
        return $this->update(['password'=>encrypt_password($data['resNewPassword']),'id'=>cache('user_id')]);
    }


    /**
     * @param $tel
     * @return array|bool|\PDOStatement|string|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 查询手机号是否存在
     */
    public function checkTel($tel){
        return $this->where('tel',$tel)->find();
    }


    /**
     * @param $tel
     * @return User
     * 修改手机号
     */
    public function changeTel($tel){
        return $this->update(['tel'=>$tel,'id'=>cache('user_id')]);
    }
}
